﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biz_Dal.Biz;

namespace Project_BookIdeas
{
    public partial class FormDoiMatKhau : Form
    {
        public FormMain frmMain;
        public FormDoiMatKhau()
        {
            InitializeComponent();
        }

        private void btnXN_Click(object sender, EventArgs e)
        {

            List<BizKhachHang> list = BizKhachHang.LoginAdmin(labUser.Text, txtMKC.Text);
            if (list.Count == 0)
            {
                MessageBox.Show("Mật khẩu cũ không đúng!", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMKC.Text = "";
                txtMKC.Focus();
            }
            else
            {
                BizKhachHang kh = User.UserDangNhap;
                kh.matKhau = txtMKMoi.Text;
                kh.updateKhachHang();
                MessageBox.Show("Đổi mật khẩu thành công!");
                User.UserDangNhap = kh;
                this.Close();

            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormDoiMatKhau_Load(object sender, EventArgs e)
        {
            labUser.Text = BizKhachHang.getKhachHangByID(frmMain.idUser).tenDangNhap;
            btnXN.Enabled = false;
        }

        private void txtMKMoiAgain_KeyUp(object sender, KeyEventArgs e)
        {
            if (txtMKMoi.Text != txtMKMoiAgain.Text || txtMKMoi.Text == "")
            {
                btnXN.Enabled = false;
                loi.SetError(txtMKMoiAgain, "Mật khẩu không khớp!");
            }
            else
            {
                btnXN.Enabled = true;
                loi.SetError(txtMKMoiAgain, "");
            }
        }

        private void txtMKMoi_KeyUp(object sender, KeyEventArgs e)
        {
            txtMKMoiAgain_KeyUp(sender, e);
        }
    }
}
